<template>
  <div class="search">
    <f-form ref="form" :action="api.expense" :form-key="this.formItem.expenseId" :file-ids="fileIds">
      <f-form-item label='部门' name='deptId' type='select' :show-search='true' :data='api.dept.list' valueKey='deptId' :value.sync='formItem.deptId' :required='true' label-key='deptName' :params='queryParam' @change='deptChange' />
      <f-form-item label='业务员' ref='saleMan' type='select' name='saleManId' :value.sync='formItem.saleManId' :data='api.saleMan.list' valueKey='saleManId' label-key='saleManName' :required='true' :params='loadSaleManParams' :autoLoad='autoLoad'   />

      <f-form-item label="申请金额" type='number' dataType='number'  name="expenseAmount" required :value="formItem.expenseAmount"/>
      <f-form-item label="款项类型" name="expenseType"  required type="select" :data="api.paymentType.list" label-key="paymentTypeName" value-key="paymentTypeCode"  :value.sync="formItem.expenseType" :showSearch="true"/>
      <f-form-item label="款项说明" name="expense"  type='textarea' required :value="formItem.expense"/>
      <f-form-item label='日期' type='date'  name='payDate' required :value='formItem.payDate' />
      <f-form-item label='收款账户' ref='bank' type='select' name='bankId' :value='formItem.bankId' :data='api.bank.list' valueKey='bankId' label-key='bankName' :required='true'   />
      <f-form-item label='备注'  type='textarea' name='remark' :value='formItem.remark' />

    </f-form>
  </div>
</template>
<script>
  import api from '../js/api'

  export default {
    name: 'expenseForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        fileIds: [],//上传文件ID
        loaded: false,//是否加载完成
        autoLoad: false,
        loadSaleManParams: {
          deptId: null
        },
        queryParam:{
          isFlp:1
        },
        formItem: this.getFormItem(),
        paymentTypeData: [
          { label: '采购预付款', value: 1 },
          { label: '快递费', value: 2 },
          { label: '销售费用', value: 3 },
          { label: '市场保证金', value: 4 },
          { label: '其他', value: 5 },
          { label: '开票税金', value: 6 }
        ]
      }
    },
    methods: {
      getFormItem() {
        return {
          expenseId: '',
          deptId: null,
          expenseNo: '',
          checkState:0,
          expense: '',
          expenseAmount: '',
          expenseType: '',
          bank: '',
          bankNo: '',
          attachmentImage: '',
          applyUserId: '',
          payUserId: '',
          payDate: '',
          createTime: '',
          updateTime: ''
        }
      },
      /**
       * 部门选择
       */
      deptChange(value) {
        this.loadSaleManParams.deptId = value
        this.$refs.saleMan.initData(this.loadSaleManParams)
        //清除已选择销售
        this.$refs.form.resetField("saleManId")
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.expenseId) {
          let params = {
            expenseId: data.expenseId
          }
          if(data.deptId){
            this.loadSaleManParams.deptId=data.deptId
            this.$refs.saleMan.initData(this.loadSaleManParams)
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //文件上传回调
      uploadSuccess(fileUrl, files, fileIds) {
        this.fileIds = fileIds
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({ }, callback)

        // this.$refs.form.submit({processInstanceId:this.formItem.processInstanceId}, callback)
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
